% Assumes that groups.dat defines the areas you want to see.
% Must be in the directory in which the simulation was run.
% function plot_net_area(area_name, type_name, num_procs);
function plot_net_area(area_name, type_name, num_procs);

connectfile='connect.dat';
[a b c d]=textread(connectfile,'%f%f%f%f%*[^\n]','delimiter','\t');
connect=[a b d]; % x y coord of area & d is cell type index.


read_groups; % Assumes groups.dat has the neural area data


index = [];
for i=1:length(areas)
    if strcmp( deblank(areas{i}), area_name) && strcmp( type_name, deblank(celltype{i})) 
        index = i
        break;
    end
end
if isempty(index)
    disp([area_name ' ' type_name ' is not in groups.dat.']);
    return;
end

%neuron_num=43511+16
neuron_num = neuron_id(index,1):num_procs:neuron_id(index,2)


synfile = [ num2str(mod(neuron_num(1),num_procs)) '-' num2str(neuron_id(end,end)+1) '.syn'];

X=load(synfile);



for kk=1:length(neuron_num)
    figure(kk)
    ind=find(X(:,1)==neuron_num(kk));
    length(ind)
    hold off
%    for ii=1:length(ind)
        % xyz=[connect(X7_19350(ind(ii),2)+1,[1,2,8]);connect(X7_19350(ind(ii),1)+1,[1,2,8])];
%        xyz0=connect(X(ind(ii),2)+1,:);
        xyz0=connect(X(ind,2)+1,:);
        plot3(xyz0(:,1),xyz0(:,2),xyz0(:,3)+1,'.');

        hold on
%    end;
    xyz1=connect(X(ind(1),1)+1,:);
    plot3(xyz1(:,1),xyz1(:,2),xyz1(:,3)+1,'r*');
    
    title(['Neurons connected to cell #: * ', num2str(neuron_num(kk))]);
    pause;
    clear ind
end;





  